package com.innoking.docsys.user.controller;

import com.innoking.docsys.search.module.SearchResultVO;
import com.innoking.docsys.search.module.SolrSearchParamVO;
import com.innoking.docsys.user.service.SolrAllTextSearchService;
import com.innoking.docsys.utils.JsonToOtherUtil;
import com.innoking.docsys.utils.OtherPojo;
import com.innoking.docsys.utils.ResultObjVO;
import com.innoking.docsys.utils.ResultUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName SolrAllTextSearchAction
 * @Description TODO 集成solr全文检索
 * @Author Administrator
 * @Date 2019/8/2 000217:26
 */
@Controller
@RequestMapping(value = "/pcwindow")
public class SolrAllTextSearchAction {

    @Autowired
    private SolrAllTextSearchService solrAllTextSearchService;

//    @Autowired
//    protected UserService userService;

    @PostMapping(value = "/searchSolrByVolOrItemOrSinItem")
    @ResponseBody
    public ResultObjVO searchSolrByVolOrItemOrSinItem(HttpServletRequest request, HttpServletResponse response,
                                                      @RequestBody String searchStr) {
        OtherPojo otherPojo = JsonToOtherUtil.rtOtherPojo(searchStr, new SolrSearchParamVO());
        SolrSearchParamVO obj = (SolrSearchParamVO) otherPojo.getObj();
        String fileText = obj.getSearchStr();
        if (StringUtils.isEmpty(fileText)) {
            return ResultUtil.paramNull("参数为空");
        }
        //判断当前用户登录状态
//        if(result1.getStatus() == 200){
        SearchResultVO newSearchResult = solrAllTextSearchService.findAllVolumeAndItemBySolr(fileText);
//        }else {
//            newSearchResult = solrAllTextSearchService. getUserVolumeAndItemBySolr(searchStr);
//        }
        return ResultUtil.success(newSearchResult);
    }

   /*public TaotaoResult selectUserIsManager() {
        TaotaoResult result = new TaotaoResult();
        Subject subject = SecurityUtils.getSubject();
        String username = (String) subject.getPrincipal();
        List<UpmsUserVO> user = userService.findByName(username);
        result =upmsUserRoleService.findUserRole(user.get(0).getUserId());
        return  result;
        return null;
    }*/

}
